var home = require("../../utils/util.js");
var url = home.home;
var url2 = home.home2;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    list:[],
    show:false,
    bgcolor: home.getKey('bgcolor'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#'+home.getKey('bgcolor'),
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
  },

  //查询股本明细列表
  getEquityList(){
    let that = this;
    wx.request({
      url: url + 'app/stock/listStockBalanceRecord',
      data:{
        storeId:home.getKey('storeId'),
        stockId:home.getKey('stockId'),
        memberId:home.getKey('userId'),
        pageNo:that.data.page,
        pageSize:10,
        name:''
      },
      method: 'GET',
      header: {
        "content-type": "application/json", // 默认
      },
      success:function (res) {
        if (res.data.code == 200) {
          let list = that.data.list;
          if (that.data.page == 1) {
            list = res.data.result.records;
          } else {
            for (let i = 0; i < res.data.result.records.length; i++) {
              list.push(res.data.result.records[i]);
            }
          }
          let show = false;
          if (list.length == 0) {
            show = true;
          }
          that.setData({list:list,show:show});
        } else {
          wx.showToast({
            title: '列表获取失败',
            icon: 'none'
          });
        }
      }
    })
  },

  //查询股本明细
  getEquity(){
    let that = this;
    wx.request({
      url: url + 'app/stock/listStockBalanceRecord',
      data:{
        storeId:home.getKey('storeId'),
        stockId:home.getKey('stockId'),
      },
      method: 'GET',
      header: {
        "content-type": "application/json", // 默认
        "X-Access-Token": home.getKey('token')
      },
      success:function (res) {
        if (res.data.code == 0) {
          if (res.data.result != null) {
            that.setData({
              equityTotal:res.data.result.equityTotal == null ? 0 : res.data.result.equityTotal,
              equityBalance:res.data.result.equityBalance
            })
          }
        } else {
          wx.showToast({
            title: '获取失败',
            icon: 'none'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      avatar:wx.getStorageSync('avatar'),
      equityTotal:home.getKey('equityTotal'),
      equityBalance:home.getKey('equityBalance'),
    })
    this.getEquityList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (e) {
    let page = this.data.page;
    this.setData({page:++page});
    this.getEquityList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})